<template>
  <div class='content'>
    <div class="profile_page">
      <head-top :go-back='goBack' :head-title="profiletitle"></head-top>
    </div>
    <div class="formContain">
      <titlebar :title-left='titleLeft'></titlebar>
      <ul>
        <li class="flex">
          <span class="label">姓名</span>
          <div>
            <van-field v-model="basicDatas.name" type="text" input-align="right" readonly/>
          </div>
        </li>
          <li class="flex">
              <span class="label">部门</span>
              <div>
                        <span style="font-size: 0.48rem">
                            {{basicDatas.deptId | dictNum('org')}}
                        </span>
              </div>
          </li>
          <li class="flex">
              <span class="label">岗位</span>
              <div>
                        <span style="font-size: 0.48rem">
                            {{basicDatas.postId | dictNum('post')}}
                        </span>
              </div>
          </li>
      </ul>

    </div>
    <div class="formContain">
      <titlebar :title-left='titleLeft1'></titlebar>
      <ul>
        <li class="flex">
          <span class="label">任务完成说明</span>
          <div>
            <span class="vtext">{{datas.taskFinishRemark}}</span>
          </div>
        </li>
        <li class="flex">
          <span class="label">上报次数</span>
          <div>
            <span class="vtext">{{datas.reportTimes}}</span>
          </div>
        </li>
        <li class="flex">
          <span class="label">上报年份</span>
          <div>
            <span class="vtext">{{datas.reportYear}}</span>
          </div>
        </li>
        <li class="flex">
          <span class="label">上报截止时间</span>
          <div>
            <span class="vtext">{{datas.taskDeadlineTime}}</span>
          </div>
        </li>
        <li class="flex">
          <span class="label">上报时间</span>
          <div>
            <span class="vtext">{{datas.taskReportTime}}</span>
          </div>
        </li>
        <li class="flex">
          <span class="label">工作进度</span>
          <div style="justify-content:inherit;font-size: 0.48rem">
            <van-slider v-model="datas.taskProgress" active-color="#ee0a24" style="justify-content:inherit;margin: 0 0.5rem" disabled>
              <template #button>
                <div class="custom-button">
                  {{ datas.taskProgress+'%' }}
                </div>
              </template>
            </van-slider>
            {{datas.taskProgress+'%' }}
          </div>
        </li>
        <li class="flex">
          <span class="label">反馈内容</span>
          <div style="min-height:2rem">
            <van-field class='full_width' style="height: 3rem;" autosize v-model="datas.feedback" type="textarea"
                       input-align="right" readonly/>
          </div>
        </li>
        <li class="flex">
          <span class="label"><i class="require">*</i>进度确认</span>
          <div @click="showpicker($event,'confirm','进度确认','getRetireData')">
            <input type="text"  placeholder="请选择" :value="datas.confirm|dictNum('getRetireData')"  readonly>
            <span class="iconfont icon-xiala"></span>
          </div>
        </li>
      </ul>
    </div>
    <div class="align_center foot-button">
      <van-button class="cancel-btn" type="primary" @click="$router.go(-1)">取消</van-button>
      <van-button class="primary-btn" type="primary" @click="saveData">提交</van-button>
    </div>
    <van-popup v-model="pickershow" position="bottom">
      <van-picker   show-toolbar  :title="title" :columns="columns" @cancel="onCancel" @confirm="onConfirm"/>
    </van-popup>
    <van-popup v-model="show" position="bottom">
      <van-datetime-picker type="date" @confirm="datetimeSelect" @cancel='cancel' v-model="currentTime"/>
    </van-popup>
  </div>
</template>

<script>
  var that;
  import headTop from '@/components/header/head'
  import titlebar from '@/components/titlebar3/titlebar3';
  import {getUserInfo, getBasicInfo, saveCertificate,getDataByTaskId,getWageAccount,updateCloseSysTask,getQuerySelf} from '@/service/getData';
  import {setStore,getStore,getDefault} from '@/assets/config/mUtils';
  import {Dialog, Toast} from 'vant';
  import MyNumberInput from '@/components/numberInput/numberInput';
  import {getUser} from '@/service/getData';

  export default {
    data() {
      return {
        company: "",//所属公司
        profiletitle: '待办事项',
        goBack: true,
        titleLeft: '基本信息',
        titleLeft1: '目标管理责任领导反馈',
        show: false, //控制日期显示隐藏
        retiredShow: false, //离退部门的显示隐藏
        pickershow: false,//控制下拉选显示隐藏
        pickerName: '',//当前控制日期的控件
        currentTime: new Date(),
        title:'标题',//下拉框标题
        fileName: '',
        basicDatas: {
          name: '',
          sex: '',
          birth: '',
          partyFigure: '',
          residentPlace: '',
          nowHomePlace: "",
        },
        datas: {
          taskFinishRemark:'',
          reportTimes:'',
          reportYear:'',
          taskDeadlineTime:'',
          taskReportTime:'',
          taskProgress :0,
          feedback:'',
          confirm:'',
        },
        partyFigureText: '',
        lookUrl: '',
        useType: 'apply',
        screenHeight: '',
        applyType: '',
        columns:[],
        codeSet:{},
        taskId:'',
        useTemp:[{ "id": "1", "text": "反馈进度低于实际进度" },{ "id": "2", "text": "反馈进度与实际相符" },{ "id": "3", "text": "反馈进度高于实际进度" }],
      }
    },
    created() {
      that = this;
      var taskType = this.$route.params.taskType;
      var empId = this.$route.params.empId;
      var taskId = this.$route.params.taskId;
      this.taskId = taskId;
      var taskRelationId = this.$route.params.taskRelationId;
      this.codeSet = this.$store.state.codeSet;

//      console.log(this.codeSet,"代码集");
      var data = {};
      data.app_userId = getStore('user_id');
      data.id = empId;
      data.CHECK_TIME = new Date().getTime().toString();
      data.CHECK_SIGN = this.$md5(data.app_userId + data.CHECK_TIME + "3a28fba00c015e0df7f88556c91cb7fc");
      getBasicInfo(data).then(res1 => {
        console.log(res1);
        this.basicDatas = res1.data;
        console.log(this.datas);
        var dict0120 = [{"pid":"-1","id":"0120000001","text":"中共党员"},{"pid":"-1","id":"0120000002","text":"预备中共党员"},{"pid":"-1","id":"0120000003","text":"共青团员"},{"pid":"-1","id":"0120000004","text":"群众"},{"pid":"-1","id":"0120000005","text":"其他"}]
        for (var i = 0; i < dict0120.length; i++) {
          if (dict0120[i].id == this.basicDatas.partyFigure) {
            this.partyFigureText = dict0120[i].text;
          }
        }

      });
      var taskData = getDefault();
      taskData.id = taskId;
      var taskUrl='/mvc/annualdeptreport/data';
      getDataByTaskId('/mvc/systask/data',taskData).then(res => {
        console.log(res);
        if(res.data!=null){
//          this.datas = res.data;
          var busData = getDefault();
          busData.id = res.data.businessId;
          getDataByTaskId(taskUrl,busData).then(res => {
            console.log(res);
            if(res.data!=null){
              this.datas = res.data;
              this.datas.taskProgress = parseFloat(res.data.taskProgress.split("%")[0]);
              this.datas.confirm = '';
              console.log(this.datas,"待办数据");
              var queryData = getDefault();
              queryData.deptReportId = res.data.id;
              getQuerySelf(queryData).then(res=>{
                console.log(res,"领导信息");
                this.datas.id = res.data.id;
                this.datas.deptReportId = res.data.deptReportId;
                this.datas.leaderId = res.data.leaderId;
                this.datas.leaderName = res.data.leaderName;
              })
            }
          })
        }
      })
    },
    mounted() {
      const _self = this;
      this.screenHeight = document.documentElement.clientHeight;
    },
    components: {
      headTop,
      titlebar,
      MyNumberInput
    },
    updated() {
      let that = this;
      this.$nextTick(function () {
        let $inputs = Array.from(document.getElementsByTagName('input'));
        /*let body = document.body;
        $inputs.forEach(item => { // 定时器是处理多个input间快速切换闪屏问题，可省略
            item.onblur = function () { // onblur是核心方法
                clearTimeout(body.timer);
                body.timer = setTimeout(() => {
                window.scroll(0, 0);
                window.innerHeight = window.outerHeight = that.screenHeight
                }, 150)
            }
            item.onfocus = function () {
                clearTimeout(body.timer)
            }
        })*/
//        let body = document.body;
//        $inputs.forEach(item => {
//          item.onblur = function () { // onblur是核心方法
//            window.scroll(0, 0);
//            window.innerHeight = window.outerHeight = that.screenHeight;
//            //console.log(that.screenHeight);
//          }
//        })
      })
    },
    filters:{
      dictNum:function(val,arg1){
        if(val!=""&&val!=undefined&&val!=null){
          if(arg1 == 'getRetireData'){
            var arr = that.useTemp.filter(item=>item.id === val);
//          console.log(val,arr);
            return arr[0].text;
          }else {
            var arr = that.codeSet[arg1].filter(item=>item.id === val);
//          console.log(val,arr);
            return arr[0].text;
          }

        }

      }
    },
    methods: {
      addZero(num){
        var addNum = num<10?"0"+num:num;
        return addNum;
      },
      datetimeSelect(value){
        this.show = false;
        var date = value;
          var val = date.getFullYear() + '-'+this.addZero(date.getMonth()+1) + '-'+ this.addZero(date.getDate());
        this.$set(this.datas,this.pickerName,val);
      },
      showpicker(event,name,title,code){
        if(code == 'getRetireData'){
          this.columns  = this.useTemp;
        }else {
          this.columns = this.codeSet[code];
        }

        this.pickershow = true;
        this.pickerName = name;
        this.title = title;
      },
      cancel() {
        this.show = false;
      },
      onConfirm(value){
        this.$set(this.datas,this.pickerName,value.id);
        this.pickershow = false;
        console.log(this.datas);
      },
      onCancel(){
        this.pickershow = false;
      },

      showdatepicker(event,name){
        this.show = true;
        this.pickerName = name;
      },
      saveData() {
        //
        if(this.datas.feedback ==''||this.datas.confirm == ''){
          Toast({
            message:'必填项不能为空!',
            duration:'1000',
          });
          return;
        }
        Toast.loading({
          duration: 0,   // 持续展示 toast
          mask: true,
          message: '正在提交...'
        });

        var data = this.datas;
        data.app_userId = getStore('user_id');
        data.CHECK_TIME = new Date().getTime().toString();
        data.CHECK_SIGN = this.$md5(data.app_userId + data.CHECK_TIME + "3a28fba00c015e0df7f88556c91cb7fc");
        data.taskProgress = data.taskProgress.toString().split("%")[0]+'%';
        console.log(data);
        var reqUrl = '/mvc/annualleaderconfirm/save';
        console.log(this.taskId);
        saveCertificate(reqUrl, data).then(res => {
          var updata = getDefault();
          updata.taskId = this.taskId;
          updateCloseSysTask(updata).then(res=>{
            Toast.clear();
            this.$router.go(-1);
          })
        })
      },

    }
  }

</script>

<style lang="scss" scoped>
  @import '../../../assets/style/mixin';
  @import '../../../assets/style/public';

  .formContain {
    background: #fff;
    ul {
      padding: 0 .54rem;
      .flex {
        justify-content: space-between;
        align-items: center;
        line-height: 2rem;
        border-bottom: 1px solid #e0e0e0;
        padding: 0 .3rem;
        &:nth-last-of-type(1) {
          border: none;
        }
        .label {
          font-size: .56rem;
          line-height: 2rem;
          color: #333333;
        }
        div {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          position: relative;
          flex-grow: 1;
          img {
            width: .68rem;
            height: .64rem;
          }
          input {
            color: #323233;
            text-align: right;
            font-size: .48rem;
            padding-right: .48rem;
            border: none;
            &:-ms-input-placeholder {
              color: #aaa;
              font-size: .48rem;

            }
          }
          .file {
            width: 2rem;
            height: 1rem;
            font-size: 10rem;
            opacity: 0;
            position: absolute;
            right: 0;
          }
          .van-cell {
            font-size: .48rem;
            padding-right: .48rem;
            padding: 0;
            color: #aaa;
            .van-field__control {
              color: #aaa;
            }
          }

        }
      }
    }
  }

  .foot-button {
    margin-top: 2rem;
    margin-bottom: .4rem;
    .cancel-btn {
      margin-right: 1rem;
    }
  }

  #datetime-picker, #picker {
    position: fixed;
    width: 100%;
    bottom: 0;
  }

  .require {
    color: red;
    margin-right: 4px;
    font-style: inherit;
    font-size: 14px;
  }
  .vtext{
    font-size: 0.48rem;
  }
  .custom-button {
    width: 30px;
    color: #fff;
    font-size: 10px;
    line-height: 18px;
    text-align: center;
    background-color: #ee0a24;
    border-radius: 100px;
  }
</style>
